﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Clotho.UI {
	public partial class AllViews : UserControl, StudioControl{
		public AllViews() {
			InitializeComponent();
			var tr = this.mainTREE.Nodes.Add("测试", "testtest", 0);
			 tr = this.mainTREE.Nodes.Add("测试1", "testtest1", 0);
			 tr = this.mainTREE.Nodes.Add("测试2", "testtest2", 0);
		}
		readonly Novel Nov;
		public static void injectTo(List<UI.ControlKeeper> controlKeepers, Novel nov, Action<ControlKeeper> dShowControl) {
			var ck = new UI.ControlKeeper(crt_str => new AllViews(nov, dShowControl), "故事总览", () => "故事总览", "GlobleSingle");
			controlKeepers.Add(ck);
		}

		public Func<string> dGetCreateString { get ; set ; }

		public string Create_str => "故事总览";
		string MutFormStudio.StudioControl.Head_text { get => "故事总览"; set { } }
		public Action dHeadTestChanged { get; set; }

		public Color Head_color => Color.LightGray;

		public ContextMenuStrip HeadContextMenuStrip => null;


		public Action<ControlKeeper> dShowControl;


		public AllViews(Novel nov, Action<ControlKeeper> dShowControl ) {
			InitializeComponent();
			Nov = nov;
			Nov.eAddContolKeeper += Nov_eAddContolKeeper;
			this.dShowControl = dShowControl;
			initNovel();
		}

		private void Nov_eAddContolKeeper(object sender, TEventArgs<ControlKeeper> e) {
			addControl(e.Value);
		}

		public void initNovel() {
			foreach(UI.ControlKeeper ck in Nov.Ui_control_enumable) {
				addControl(ck);
			}
		}

		private void addControl(ControlKeeper ck) {
			TreeNode tr = this.mainTREE.Nodes.Add(ck.Head_text, ck.Head_text, 0);
			tr.Tag = ck;
			tr.ImageKey = ck.Control_type;
			tr.SelectedImageKey = ck.Control_type;
			ck.eHeadTextChanged += (s,e)=> tr.Text = ck.Head_text;
		}


		private void mainTREE_DoubleClick(object sender, EventArgs e) {
			var ck = mainTREE.SelectedNode.Tag as ControlKeeper;
			dShowControl.Invoke(ck);
		}

		public void setHeadText(string head_text) {

		}
	}



}
